package com.fcl.blog.service.impl;

import com.fcl.blog.mapper.BlogMapper;
import com.fcl.blog.po.Blog;
import com.fcl.blog.po.BlogTags;
import com.fcl.blog.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author 付
 * @Date 2023/10/24 12:12
 * @Version 1.0
 * @description
 * @since 1.0
 */
@Service
public class BlogServiceImpl implements BlogService {

    @Autowired
    private BlogMapper blogMapper;
    @Override
    public List<Blog> selectListBlog() {
        return blogMapper.selectListBlog();
    }

    @Override
    public List<Blog> selectListAdminBlog() {
        return blogMapper.selectListAdminBlog();
    }

    @Transactional
    @Override
    public int insertBlog(Blog blog) {
        return blogMapper.insertBlog(blog);
    }


    @Transactional
    @Override
    public int insertBlogTags(BlogTags blogTags) {
        return blogMapper.insertBlogTags(blogTags);
    }

    @Override
    public List<Blog> searchBlog(String title, String typeId) {
        return blogMapper.searchBlog(title,typeId);
    }

    /**
     * 这里和客户端的区别也是发表和未发表的文章的查询与否
     * @param title
     * @param typeId
     * @return
     */
    @Override
    public List<Blog> searchAdminBlog(String title, String typeId) {
        return blogMapper.searchBlog(title,typeId);
    }

    @Transactional
    @Override
    public int deleteById(Long id) {
        return blogMapper.deleteById(id);
    }

    /**
     * 用户端时不需要查询草稿文章的，也就是不查询未发表的文章
     * @return
     */
    @Override
    public Long blogCount() {
        return blogMapper.blogCount();
    }

    /**
     * 由于管理端时不管发布还是草稿都需要查询的
     * @return
     */
    @Override
    public Long blogAdminCount() {
        return blogMapper.blogAdminCount();
    }


    /**
     * 查询最新推荐文章，按照发表的时间 先后排序查询
     * @return
     */
    @Override
    public List<Blog> selectNewRecommend() {
        return blogMapper.selectNewRecommend();
    }

    @Override
    public List<Blog> selectByTypeId(Long id) {
        return blogMapper.selectByTypeId(id);
    }


}
